<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <!-- 以class的方式创建类 -->
    <script>
        class Person{
            constructor(name,age,sex,skill){
                this.name = name;
                this.age = age;
                this.sex = sex;
                this.skill = skill;
            }
            sayName(){
                console.log(this.name);
            }
        }

        //直接添加原型方法
        Person.prototype.sayAge = function(){
            console.log(this.age);
        }

        // 字面量的形式添加原型方法    **不可以
        // Person.prototype = {
        //     saySex(){
        //         console.log(this.sex);
        //     }
        // }

        // 以Object.assign的方法
        Object.assign(Person.prototype,{
            saySex(){
                console.log(this.sex);
            },
            saySkill(){
                console.log(this.skill);
            }
        })
        var p = new Person("cc",18,"man","js");
        console.log(p);
        p.sayAge();
        p.saySex();
        p.saySkill();

    </script>
</body>
</html>